import { defineStore } from 'pinia'

export const useCart = defineStore('cart', {
  // 为了完整类型推理，推荐使用箭头函数
  state: () => {
    return {
      shoppingCart: {}, // 购物车列表
      cartNumber: 0, // 购物车数量
      evaluateOrders: {} // 评价订单
    }
  },
  // getters: {
  //   getCartNumber: (state) => state.cartNumber,
  // },
  actions: {
    setShoppingCart (data) {
      this.shoppingCart = data
    },
    setCartNumber (data) {
      this.cartNumber = data
    },
    setEvaluateOrders (data) {
      this.evaluateOrders = data
    }
  },
  persist: {
    enabled: true,
    strategies: [
      {
        storage: localStorage, // 默认存储在sessionStorage里
        // paths: ['cartNumber']  // 指定存储state，不写则存储所有
      }
    ]
  }
})